import keyboard
import os
import signal
import threading
import time
import sys
import pyautogui


def exit_():
    keyboard.wait('esc')
    os.kill(os.getpid(),signal.SIGINT)

def loop_click(s=1):
    pyautogui.alert(text='移动鼠标到连续点击位置，\n按enter键开始，\n按esc键盘结束')
    keyboard.wait('enter')
    x,y=pyautogui.position()
    print(x,y)
    threading.Thread(target=exit_).start()
    while True:
        time.sleep(s)

        pyautogui.click(x,y)

def get_delay():
    while True:
        s=pyautogui.prompt(text='请输入点击时间间隔单位s，点击取消将推出程序',title='疯狂点击',default=1)
        if not s:
            sys.exit(0)
        try:
            s=float(s)
            break
        except:
            pyautogui.alert(text='请输入合法数字')
            continue
    return s

def main():
    s=get_delay()
    loop_click(s=s)


if __name__ == '__main__':
    main()